package com.trickytriad.model.repositories
{
	import com.trickytriad.events.game.GetGameDataEvent;
	import com.trickytriad.model.GameData;
	
	import flash.utils.Dictionary;
	
	/**
	 * Repository for GameData.  Stores retrieved GameData in a Dictionary object.
	 * 
	 * Through Parsley, all repositories are singletons.
	 * 
	 */
	public class R_GameData
	{		
		// Dictionary of game data
		private var _dict:Dictionary;

		public function R_GameData()
		{
		}

		/**
		 * Function that retrieves the game data requested, either from the dictionary or by requesting from the server.
		 * @param uint GameID of the object to retrieve.
		 * @param Function Completion handler function
		 * @param Function Error handler function (optional)
		 */
		public function retrieveGameData(in_gid:uint, in_completeHandler:Function, in_errorHandler:Function=null) : void
		{
			var gdata:GameData = (_dict[in_gid.toString()] as GameData);
			if (gdata != null) // We have the game data already stored
			{
				in_completeHandler(new GetGameDataEvent(GetGameDataEvent.GETGAMEDATA_DONE, 0, gdata));
			}
			else // Not found, so we'll call up the service to retrieve it
			{
			
			}
			
		}


	}
}